package com.intellagric.controller.product;

import com.intellagric.common.bean.LayuiDataGridResult;
import com.intellagric.common.bean.ResponseMessage;
import com.intellagric.common.utils.UUIDUtils;
import com.intellagric.interfaces.product.ProductCategoryService;
import com.intellagric.pojo.ProductCategory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/admin")
public class ProductCategoryController {

    @Autowired
    private ProductCategoryService productCategoryService;

    @RequestMapping("/productCategory/add")
    @ResponseBody
    public ResponseMessage addProductCategory(ProductCategory ProductCategory){
        ProductCategory.setId(UUIDUtils.getID());
        ProductCategory.setCreateDate(new Date(System.currentTimeMillis()));
        return productCategoryService.insertProductCategory(ProductCategory);
    }

    @RequestMapping("/productCategory/edit")
    @ResponseBody
    public ResponseMessage editProductCategory(ProductCategory ProductCategory){
        return productCategoryService.editProductCategory(ProductCategory);
    }

    @RequestMapping("/productCategory/delete")
    @ResponseBody
    public ResponseMessage deleteProductCategory(String id){
        return productCategoryService.deleteProductCategory(id);
    }

    @RequestMapping("/productCategory/batchdelete")
    @ResponseBody
    public LayuiDataGridResult batchDelete(@RequestParam("ids[]") String[] ids){
        return productCategoryService.batchDeleteProductCategory(ids);
    }

    @RequestMapping("/productCategory/getProductCategory")
    @ResponseBody
    public ProductCategory getProductCategory(String ProductCategoryId){
        return (ProductCategory) productCategoryService.selectProductCategoryById(ProductCategoryId).getData().get("categoryBean");
    }



    @RequestMapping("/productCategory/menu")
    @ResponseBody
    public LayuiDataGridResult getMenu(){
        return productCategoryService.getMenu();
    }

    @RequestMapping("/productCategory/search")
    @ResponseBody
    public LayuiDataGridResult search(int page, int limit, String keyword){
        return productCategoryService.getProductCategoryByKeyword(page,limit,keyword);
    }
    /**
     * 查询菜单树信息
     * @return LayuiDataGridResult
     */
    @RequestMapping("/productCategory/treelist")
    @ResponseBody
    public List<ProductCategory> getTreeList() {
        LayuiDataGridResult category=productCategoryService.getMenu();
        return category.getData();
    }

}
